//
//  MenuGroupManager.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/24.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "MenuContentManager.h"
#import "GXMenuGroupModel.h"
#import "GXFeatureModel.h"
@implementation MenuContentManager

+ (void)selectMenuGroupWithStoreID:(NSString*)storeId
               success:(CompleteHandle)success
                              fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"FIND_DISHES_GROUP_S",
                @"parameters":@{
                        @"storeId":storeId,
                        }
                };
    [HttpHelper Post:@"ycs/Dishes/Dishes.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD dismiss];
                NSDictionary * contentDic = responseObject[@"result"];
                NSMutableArray * dataArray = [NSMutableArray array];
                if (![contentDic[@"dishess"] count]) {
                    [SVProgressHUD showImage:nil status:@"无数据"];
                }else
                {
                    for (NSDictionary *dict in contentDic[@"dishess"]) {
                        GXMenuGroupModel *model = [GXMenuGroupModel mj_objectWithKeyValues:dict];
                        [dataArray addObject:model];
                    }
                }
                success(dataArray);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}


+ (void)addMenuGroupWithStoreID:(NSString*)storeId groupName:(NSString *)name
                        success:(CompleteHandle)success
                           fail:(CompleteHandle)fail
{
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"INSERT_DISHES",
                @"parameters":@{
                        @"storeId":storeId,
                        @"name":name
                        }
                };
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
    [HttpHelper Post:@"ycs/Dishes/Dishes.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"添加分组成功"];
            success(responseObject);
        }else
        {
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}
+ (void)deleteMenuGroupWithSdishesId:(NSString *)dishesId
                        success:(CompleteHandle)success
                              fail:(CompleteHandle)fail{
    [SVProgressHUD showWithStatus:@"删除中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"DELETE_DISHES",
                @"parameters":@{
                        @"dishesId":dishesId
                        }
                };
    [HttpHelper Post:@"ycs/Dishes/Dishes.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"删除成功"];
            success(responseObject);
        }else
        {
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}
+ (void)changeMenuGroupNameWithSdishesId:(NSString *)dishesId groupName:(NSString *)name
                             success:(CompleteHandle)success
                                fail:(CompleteHandle)fail{
     [SVProgressHUD showWithStatus:@"更改中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"UPDATE_DISHESGROP_NAME",
                @"parameters":@{
                        @"dishesId":dishesId,
                        @"name":name
                        }
                };
    [HttpHelper Post:@"ycs/Dishes/Dishes.do"  parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"更改分组成功"];
            success(responseObject);
        }else
        {
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
         [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)moveMenuGroupWithStoreId:(NSString *)storeId dishesgropS:(NSArray *)changeArray
                             success:(CompleteHandle)success
                                fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"移动中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"UPDATE_DISHESGROP_LIST",
                @"parameters":@{
                        @"storeId":storeId,
                        @"dishesgropS":changeArray
                        },
                };
    [HttpHelper Post:@"ycs/Dishes/Dishes.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"移动成功"];
            success(responseObject);
        }else
        {
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
   
}


+ (void)selectMenuListWithStoreID:(NSString*)storeId
                           success:(CompleteHandle)success
                             fail:(CompleteHandle)fail{
     [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"SELECT_SERVICE_LIST",
                @"parameters":@{
                        @"storeId":storeId,
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD dismiss];
                success(responseObject);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
         [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
    
}

+ (void)addDishWithStoreID:(NSString*)storeId  dishesName:(NSString *)name  dishesImage:(NSString *)imageStr describerStr:(NSString *)describer dishesId:(NSString *)dishesId priceStr:(NSString *)price discountPrice:(NSString *)discountPrice success:(CompleteHandle)success  fail:(CompleteHandle)fail{
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
     NSDictionary * jsonStr = [NSDictionary dictionary];
     jsonStr = @{@"api":@"INSERT_SERVICE",
                @"parameters":@{
                        @"dishesImage":imageStr,
                        @"name":name,
                        @"storeId":storeId,
                        @"describer":describer,
                        @"dishesId":dishesId,
                        @"price":price,
                        @"discountPrice":discountPrice
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD showSuccessWithStatus:@"添加成功"];
                success(responseObject);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)selectSingleDishWithServiceId:(NSString*)serviceId  success:(CompleteHandle)success  fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"SELECT_SERVICE_SERVICEX",
                @"parameters":@{
                        @"serviceId":serviceId
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                success(responseObject);
                [SVProgressHUD dismiss];
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)changeDishWithServiceId:(NSString *)serviceId dishesName:(NSString *)name dishesImage:(NSString *)imageStr describerStr:(NSString *)describer dishesId:(NSString *)dishesId priceStr:(NSString *)price discountPrice:(NSString *)discountPrice success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"UPDATE_SERVICE",
                @"parameters":@{
                        @"dishesImage":imageStr,
                        @"name":name,
                        @"serviceId":serviceId,
                        @"describer":describer,
                        @"dishesId":dishesId,
                        @"price":price,
                        @"discountPrice":discountPrice
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                success(responseObject);
                [SVProgressHUD showSuccessWithStatus:@"修改成功"];
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}


+ (void)selectFeatureFuctionWithStoreId:(NSString*)storeId  sige:(NSString*)sige  success:(CompleteHandle)success  fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"SELECT_SERVICE_TSSERVICE",
                @"parameters":@{
                        @"storeId":storeId,
                        @"sige":sige
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD dismiss];
                NSDictionary *contentDic = responseObject[@"result"];
                if (![contentDic[@"serviceS"] count]) {
                    [SVProgressHUD showImage:nil status:@"无数据"];
                }else
                {
                    NSMutableArray *dataArray = [NSMutableArray array];
                    for (NSDictionary * dict in contentDic[@"serviceS"]) {
                        GXFeatureModel * model = [GXFeatureModel mj_objectWithKeyValues:dict];
                        [dataArray addObject:model];
                    }
                    success(dataArray);
                }
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}


+ (void)selectAllFeatureDataSourceWithStoreId:(NSString*)storeId  success:(CompleteHandle)success  fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"SELECT_SERVICE_TSSERVICE",
                @"parameters":@{
                        @"storeId":storeId,
                        @"sige":@""
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD dismiss];
            success(responseObject);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}



+ (void)addFeatureFuctionWithServiceId:(NSString*)serviceId  sige:(NSString*)sige  success:(CompleteHandle)success  fail:(CompleteHandle)fail{
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"ADD_SERVICE_CPSIGE",
                @"parameters":@{
                        @"serviceId":serviceId,
                        @"sige":sige
                        }
                };
    [HttpHelper Post:@"ycs/ServiceC/ServiceC.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD showSuccessWithStatus:@"添加成功"];
                success(responseObject);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}


@end
